//
//  GivingTableViewCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/19.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "GivingTableViewCell.h"

@implementation GivingTableViewCell

- (void)setupUI{
    
    self.backgroundColor = KWhiteColor;
    
    [self addSubview:self.userNamePhoneLab];
    [self addSubview:self.locationLab];
    [self addSubview:self.nameLab];
    [self addSubview:self.fallbackBtn];
    
    [self addSubview:self.numberLab];
    [self addSubview:self.arrowBtn];
    [self addSubview:self.pigTypeNOLab];
    
    
    [self.icons enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        UIImageView *icon = (UIImageView *)obj;
        [self addSubview:icon];
    }];

}


- (void)setupLayout
{
    CGFloat width = KScreenWidth - 30;
    
    {
        _userNamePhoneLab.size = CGSizeMake(width - 30, 22);
        _userNamePhoneLab.mj_x = _userNamePhoneLab.mj_y = 15;
    }

    
    {
        _locationLab.mj_x = 36;
        _locationLab.height = 35;
        _locationLab.mj_y = _userNamePhoneLab.bottom + 7;
        _locationLab.width = width - 120;
    }
    
    
    {
        _fallbackBtn.size = CGSizeMake(50, 26);
        _fallbackBtn.mj_x = width - _fallbackBtn.width - 15;
        _fallbackBtn.mj_y = 34;
    }
    
    
    {
        CAShapeLayer *line = [CAShapeLayer layer];
        line.fillColor = mBackgroudColor.CGColor;
        UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(35, 91, width - 51, 1)];
        line.path = path.CGPath;
        [self.layer addSublayer:line];
    }
    
    
    {
        _nameLab.frame =  CGRectMake(0, 0, 200, 44);
        [_nameLab sizeToFit];
        _nameLab.mj_x = 36;
        _nameLab.mj_y = _locationLab.bottom + 25;
    }
    
    
    {
        _pigTypeNOLab.frame =  CGRectMake(0, 0, 200, 44);
        [_pigTypeNOLab sizeToFit];
        _pigTypeNOLab.mj_x = _nameLab.right + 5;
        _pigTypeNOLab.mj_y = _nameLab.mj_y;
    }
    
    {
        _numberLab.size = CGSizeMake(100, 20);
        _numberLab.mj_y = 144;
        _numberLab.mj_x = width - _numberLab.width - 31;
    }
    
    {
        _arrowBtn.size = CGSizeMake(16, 16);
        _arrowBtn.mj_y = _numberLab.mj_y + 2;
        _arrowBtn.mj_x = _numberLab.right;
    }
    
    
    NSMutableAttributedString *atttibutedStr = [@"张烨 185****1762" createAttributingByIcon:@"address_tip" downIndexImage:nil textColor:UIColorFromRGB(0x262626) font:mFont(16)];
    _userNamePhoneLab.attributedText = atttibutedStr;
    _numberLab.text = @"共4件";
    
}


#pragma mark - setter methods


#pragma mark - getter methods

- (UILabel *)userNamePhoneLab{
    
    if (!_userNamePhoneLab) {
        _userNamePhoneLab = [UILabel new];
    }
    return _userNamePhoneLab;
}


- (UILabel *)locationLab{
    
    if (!_locationLab) {
        _locationLab = [UILabel makeLabelWithText:@"地址：天津市武清开发区创业总部基地B座15号楼1208室、1205室" textColor:UIColorFromRGB(0x666666) font:mFont(12) textAliment:0];
        _locationLab.numberOfLines = 0;
    }
    return _locationLab;
}


- (UIButton *)fallbackBtn{
    
    if (!_fallbackBtn) {
        _fallbackBtn = [UIButton makeButtonWithText:@"撤回" textColor:UIColorFromRGB(0x454545) font:mFont(13) textAliment:1 cornerRadius:5];
        _fallbackBtn.layer.borderColor = UIColorFromRGB(0xD8D8D8).CGColor;
        _fallbackBtn.layer.borderWidth = 1;
        
        @weakify(self);
        _fallbackBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealFallbackBlock) {
                self.dealFallbackBlock();
            }
        };

    }
    
    return _fallbackBtn;
}



- (UILabel *)nameLab{
    
    if (!_nameLab) {
        _nameLab = [UILabel makeLabelWithText:@"三元仔猪" textColor:UIColorFromRGB(0x333333) font:mFont(13) textAliment:0];
    }
    return _nameLab;
}


- (UILabel *)pigTypeNOLab{
    
    if (!_pigTypeNOLab){
        _pigTypeNOLab = [UILabel makeLabelWithText:@"编号A1812240001" textColor:UIColorFromRGB(0x666666) font:mFont(13) textAliment:0];
    }
    return _pigTypeNOLab;
}


- (UIButton *)arrowBtn{
    
    if (!_arrowBtn) {
        _arrowBtn = [UIButton makeButtonWithImageName:@"meat_cart_enter"];
        _arrowBtn.contentMode = UIControlContentHorizontalAlignmentRight;
        
        @weakify(self);
        _arrowBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealShopListBlock) {
                self.dealShopListBlock();
            }
        };
    }
    return _arrowBtn;
}


- (UILabel *)numberLab
{
    
    if (!_numberLab) {
        _numberLab = [UILabel makeLabelWithText:@"1111111" textColor:UIColorFromRGB(0x999999) font:mFont(12) textAliment:2];
        
        @weakify(self);
        _numberLab.tapBlock = ^{
            @strongify(self);
            if (self.dealShopListBlock) {
                self.dealShopListBlock();
            }
        };
    }
    return _numberLab;
}


- (NSMutableArray *)icons{
    
    if (!_icons) {
        _icons = [NSMutableArray array];
        
        for (NSInteger i = 0; i< 5; i++) {
            
            UIImageView *icon = [UIImageView makeImageByImageName:@"p1" cornerRadius:8];
            icon.tag = 500 + i;
            icon.size = CGSizeMake(40, 40);
            icon.mj_x = 36 + (45)*i;
            icon.mj_y = 134;
            
            [_icons addObject:icon];
        }
    }
    return _icons;
}


@end
